import { ElMessage } from "element-plus";
import { getAllList as locationgetAllList } from "../api/location.js";
//消息提示
export function toast(
  message,
  type = "success",
  dangerouslyUseHTMLString = false,
  duration = 2000
) {
  ElMessage({
    message,
    type,
    duration,
    dangerouslyUseHTMLString,
  });
}

//将时间戳格式化为年月日时分秒的格式
export function formatDate(timestamp) {
  const date = new Date(timestamp);

  const year = date.getFullYear();
  const month = ("0" + (date.getMonth() + 1)).slice(-2); // 补零
  const day = ("0" + date.getDate()).slice(-2);
  const hours = ("0" + date.getHours()).slice(-2);
  const minutes = ("0" + date.getMinutes()).slice(-2);
  const seconds = ("0" + date.getSeconds()).slice(-2);

  const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  return formattedDate;
}

//将时间戳格式化为年份格式
export function formatYear(timestamp) {
  const date = new Date(timestamp);
  return date.getFullYear();
}

export function generateAcademicYears(startYear) {
  const currentYear = new Date().getFullYear();
  const numberOfYears = currentYear - startYear + 1; // 计算学年的数量
  const academicYears = [];

  for (let i = 0; i < numberOfYears; i++) {
    const startYearLabel = startYear + i;
    const endYearLabel = startYearLabel + 1;
    const academicYear = `${startYearLabel}-${endYearLabel}`;

    academicYears.push(`${academicYear}学年`);
  }

  return academicYears;
}
